package com.provider.ostrich.controller;

import com.alibaba.fastjson.JSON;
import com.provider.ostrich.feignApi.HelloWorld;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author HuTongFu
 * @description:
 * @since 2019/6/21 13:38
 */
@Slf4j
@RestController
@RequestMapping("/provider")
public class TestController {

    @GetMapping("/testFeignApi")
    @ResponseBody
    public HelloWorld testFeignApi(@RequestParam("param") String param) {
        System.out.println(param + "我被调用了");
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setParam(param);
        return helloWorld;
    }

    @PostMapping("/testFeignProviderHasParameter/{id}")
    public HelloWorld testFeignProviderHasParameter(@PathVariable String id) {
        System.out.println(id + "我被调用了");
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setParam(id);
        return helloWorld;
    }


    /**
     * 接收一个对象
     *
     * @param helloWorld
     * @return
     */
    @PostMapping("/testFeignProviderHasParameterB")
    public HelloWorld testFeignApiHasParameterBJson(HelloWorld helloWorld) {
        System.out.println(helloWorld + "我被调用了");
        helloWorld.setParam(JSON.toJSONString(helloWorld));
        return helloWorld;
    }
}
